<?php
namespace app\model;

use support\Model;

class Order extends Model
{
    protected $table = 'ky_order';
    protected $primaryKey = 'order_id';
    protected $fillable = [
        'order_no',
        'card_no',
        'scenic_spot_id',
        'contact_name',
        'contact_phone',
        'total_amount',
        'pay_amount',
        'status',
        'pay_type',
        'pay_time',
        'remark'
    ];

    protected $casts = [
        'total_amount' => 'float',
        'pay_amount' => 'float',
        'pay_time' => 'datetime'
    ];

    /**
     * 获取订单明细
     */
    public function items()
    {
        return $this->hasMany(OrderItem::class, 'order_id', 'order_id');
    }

    /**
     * 获取景区
     */
    public function scenicSpot()
    {
        return $this->belongsTo(ScenicSpot::class, 'scenic_spot_id', 'scenic_spot_id');
    }

    /**
     * 获取黑卡
     */
    public function blackCard()
    {
        return $this->belongsTo(BlackCard::class, 'card_no', 'card_no');
    }
} 